<?php
/**
 * 事件消息处理帮助方法
 *
 * Author: Zeon
 * Date: 2017/7/21
 * Time: 16:24
 * Created by PhpStorm.
 */
namespace App\Services\OpenWechat;

use App\Models\Goat\Goat;
use App\Models\Goat\ScanCode;
use App\Models\Goat\Staff;
use App\Models\Goat\WechatUser;
use App\Models\OpenWechat\Authorizer;
use App\Services\OpenWechat\AppFactory;
use App\Services\OpenWechat\Contracts\AppServer;
use App\Services\OpenWechat\Mock;
use App\Services\OpenWechat\Goat\WechatUserRepository;
use App\Services\Utils\Transaction;
use BindStaffInfo;
use EasyWeChat\Foundation\Application;
use EasyWeChat\Support\Collection;
use App\Services\Utils\ApiChecker;
use App\Services\Utils\ApiResponser;
use Illuminate\Support\Str;
use StoreWechatUser;


class EventMessageHelper
{
    const SUBSCRIBE_EVENT_KEY_PREFIX = 'qrscene_';

    /**
     * 判断扫码消息是否是订阅
     *
     * @param $event_key
     * @return string
     */
    public static function isKeySubscribe($event_key)
    {
        return Str::startsWith($event_key, self::SUBSCRIBE_EVENT_KEY_PREFIX);
    }

    /**
     * @example
     *      extractEventKey('qrscene_MIR_XXX:1') => MIR_XXX:1
     *
     * @param $event_key
     * @return string
     */
    public static function normalizeEventKey($event_key)
    {
        return last(explode(self::SUBSCRIBE_EVENT_KEY_PREFIX, $event_key));
    }

}